import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/reports.dart';
import 'package:ichinesereader/pages/common/report/reportsStudentPersonalContent.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/charts/levelProgressChart.dart';

class ReportsStudentPersonalLevel extends StatefulWidget {
  ReportsStudentPersonalLevel({Key? key, required this.userName})
      : super(key: key);
  final String userName;

  @override
  ReportsStudentPersonalLevelState createState() =>
      ReportsStudentPersonalLevelState();
}

class ReportsStudentPersonalLevelState
    extends State<ReportsStudentPersonalLevel> {
  final ReportsController _reportsController = Get.find();

  @override
  void initState() {
    studentPersonalReportTab = Constants.studentPersonalReportTabs[6];
    if (_reportsController.studentLevelProgress.isNotEmpty) {
      _reportsController.studentLevelProgress.clear();
    }
    fetchData(this.widget.userName);
    super.initState();
  }

  void fetchData(String userName) {
    Future.delayed(Duration(milliseconds: 200), (() {
      _reportsController.fetchStudentLevelProgress(userName);
    }));
  }

  @override
  Widget build(BuildContext context) {
    Log.debug('build reports student personal level progress');
    return Column(
      children: [
        Obx(() {
          if (_reportsController.studentLevelProgress.isNotEmpty) {
            return LevelProgressChart(
                levelchartdata: _reportsController.studentLevelProgress);
          } else {
            return Center(
                child: Container(child: Text('Data not available ...'.tr)));
          }
        })
      ],
    );
  }
}
